The present invention relates to a method, program, and information processing apparatus for handling strings.
Computers, which are information processing apparatuses, conventionally operate in accordance with a program written in a programming language such as C or Java. The computer stores data such as numeric values and strings used in arithmetic in a memory which is a storage.
For example, in a computer operating in accordance with a Java program written in Java, which is an object-oriented language, garbage collection (hereinafter referred to as GC) that automatically frees a memory area in a memory that stores data that is no longer in use, without intervention of a programmer is used. In one GC implementation, a memory is divided into two memory areas, a first memory area storing a first type of data group having a relatively short lifetime and a second memory area storing a second type of data group having a relatively long lifetime, and GC is executed more frequently on the first memory area than on the second memory area. In this way, GC is limited to a particular memory area in consideration of the characteristics of data, thereby efficiently freeing the memory area.
As described above, a computer operating in accordance with a Java program executes GC to free memory areas to reduce the amount of data stored in a memory used by the computer.
In a typical implementation of an execution environment of the Java program described above, strings represented by String objects are referred to in char array objects. The char array object generally has two characteristics.
A first characteristic is that a char array object may contain char data that is not referenced as a string of a String object. If such a char array object is not referred to by objects other than a String object, it is desirable that the memory area in which the char data that is not referenced as a string of the string object be freed to save the memory space consumed by the computer.
A second characteristic is that there may be multiple char array objects that have the same string data. In Java, strings of String objects cannot be handled. In the above case, it is desirable that two identical char array objects be consolidated into one and the memory area that stores one of the objects be freed to reduce the memory space consumed by the computer.
However, in a computer operating according to a Java program, conventional GC typically cannot detect char data that is not referred to or redundant char array objects described above among a group of char array objects and therefore cannot free memory areas storing these kinds of data. Therefore, there has been a problem that the amount of data stored in a memory used by the computer cannot sufficiently be reduced.